package com.bjgzy.rating.mvp.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bjgzy.rating.R;
import com.bjgzy.rating.R2;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eduhzy.ttw.commonres.utils.RxUtil;
import com.eduhzy.ttw.commonsdk.core.RouterHub;
import com.eduhzy.ttw.commonsdk.decoration.RecycleViewDivider;
import com.eduhzy.ttw.commonsdk.entity.EntriesDetailData;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;
import com.jess.arms.base.BaseFragment;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.mvp.IView;
import com.jess.arms.utils.ArmsUtils;
import com.qmuiteam.qmui.widget.dialog.QMUITipDialog;

import java.util.List;

import butterknife.BindView;

import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * @author xubo
 * @date 2018-8-30 22:17:20
 */
@Route(path = RouterHub.RATING_DOCUMENTFRAGMENT)
public class DocumentFragment extends BaseFragment implements IView {

    @BindView(R2.id.rv_list)
    RecyclerView mRvList;

    BaseQuickAdapter<EntriesDetailData.AttachmentListBean, AutoBaseViewHolder> mAdapter;

    private List<EntriesDetailData.AttachmentListBean> lists;

    public static DocumentFragment newInstance() {
        DocumentFragment fragment = new DocumentFragment();
        return fragment;
    }

    @Override
    public void setupFragmentComponent(@NonNull AppComponent appComponent) {
    }

    @Override
    public View initView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.rating_fragment_document, container, false);
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        mAdapter = new BaseQuickAdapter<EntriesDetailData.AttachmentListBean, AutoBaseViewHolder>(R.layout.rating_rv_item_document, lists) {
            @Override
            protected void convert(AutoBaseViewHolder helper, EntriesDetailData.AttachmentListBean item) {
                helper.setText(R.id.tv_name, item.getDisplayName());
                Glide.with(mContext)
                        .load(item.getImg())
                        .apply(RequestOptions.placeholderOf(R.drawable.public_img_default).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL))
                        .into((ImageView) helper.getView(R.id.iv_icon));
            }
        };
        mRvList.setAdapter(mAdapter);
        mRvList.setLayoutManager(new LinearLayoutManager(getActivity()));
        mRvList.addItemDecoration(new RecycleViewDivider(getActivity(), LinearLayoutManager.VERTICAL, 1, getResources().getColor(R.color.public_color_CCCCCC)));
    }


    @Override
    public void setData(@Nullable Object data) {
        lists = (List<EntriesDetailData.AttachmentListBean>) data;
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        RxUtil.showTipDialog(getActivity(), QMUITipDialog.Builder.ICON_TYPE_NOTHING, message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {

    }

}
